<?php
//======================================================================================
//
// Function: Read integration logfile
//
// Programmer: AR
// Date : 2025-06-13
//
// Copyright Reeft A/S (c) - 2025
//======================================================================================
// datatables parameters:
// https://datatables.net/manual/server-side
//======================================================================================
// General config
//======================================================================================
include "config/config.php";
//======================================================================================
// Set language
//======================================================================================
include "include/set_language.php";
//======================================================================================
// Get input
//======================================================================================
if (isset($_REQUEST["filePath"])) {
$filePath = $_REQUEST["filePath"];
} else {
echo json_encode(['error' => 'filePath missing']);
exit;
}
if (isset($_REQUEST["fileformat_codepage"])) {
$codepage = $_REQUEST["fileformat_codepage"];
} else {
$codepage = 'windows-1252';
}
//======================================================================================
// Read file
//======================================================================================
if (file_exists($filePath)) {
$lines = file($filePath, FILE_IGNORE_NEW_LINES); // Read lines into an array
// Convert the content to the UTF-8 so json can use it
$convertedLines = [];
foreach ($lines as $line) {
$convertedLines[] = iconv($codepage, 'UTF-8' . '//TRANSLIT', $line); //The //TRANSLIT option in iconv attempts to transliterate characters that cannot be represented in the target encoding
}
echo json_encode($convertedLines); // Encode the lines as JSON
} else {
echo json_encode(['error' => 'File not found']);
}
exit;
?>